package com.star.util;

import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URL;

/**
 * @Classname PathUtil
 * @Author Star
 * @Date 2021/4/15 - 10:40
 * @Description 存取图片路径
 */
public class PathUtil {
    //获取当前系统的分隔符是什么
    private static final String separator = System.getProperty("file.separator");
    //获取图片的根路径
    public static String getImgBase(){
        //获取登录的是什么端 pc 移动
        String os = System.getProperty("os.name");
        String basePath = "";
        if(os.toLowerCase().startsWith("win")){
            basePath = "F:/Img";
        }else {
            basePath = "/home/starorange/img";
        }
        basePath = basePath.replace("/",separator);
        return basePath;
    }
    //返回店铺路径 上传路径
    public static String getShopImgPath(long shopId){
        String imgPath = "/upload/item/shop/"+shopId+"/";
        imgPath.replace("/",separator);
        return imgPath;
    }
    //返回用户头像路径 上传路径
    public static String getUserInfoImgPath(long userId){
        String imgPath = "/upload/item/userInfo/"+userId+"/";
        imgPath.replace("/",separator);
        return imgPath;
    }
    //获取当前项目资源路径
    public static String getURL(HttpServletRequest request){
        return request.getScheme()+"://"+request.getServerName()+":"
                +request.getServerPort() + request.getContextPath();
    }
}
